package com.huluobo.a2111douyindemo.startLive;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm_base.mvvm.base.model.BaseRepo;
import com.huluobo.mvvm_base.mvvm.bean.PushBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.StopPushBeanResult;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/3/11.
 */
public class StartLiveRepo extends BaseRepo {
    public void startPush(RequestBody body, MutableLiveData<PushBeanResult> success, MutableLiveData<String> failed) {
        apiService.startPush(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PushBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PushBeanResult pushBeanResult) {
                        success.setValue(pushBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void stopPush(MutableLiveData<StopPushBeanResult> success, MutableLiveData<String> failed) {
        apiService.stopPush()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StopPushBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StopPushBeanResult stopPushBeanResult) {
                        success.setValue(stopPushBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
